/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2019年1月7日
 */

package com.massyframework.beanskin.spring.beancontext;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import com.massyframework.beanskin.assembly.Assembly;

import java.util.Objects;

/**
 * {@link AssemblyDependencyServiceInitalizer}, 提供装配件依赖服务的注入
 */
public class AssemblyDependencyServiceInitalizer<C extends ConfigurableApplicationContext> 
	implements ApplicationContextInitializer<C> {

    private final Assembly assembly;
    private final BeanFactoryPostProcessor processor;

    public AssemblyDependencyServiceInitalizer(Assembly assembly, BeanFactoryPostProcessor processor) {
        this.assembly = Objects.requireNonNull(assembly, "\"assembly\" cannot be null.");
        this.processor = Objects.requireNonNull(processor, "\"processor\" cannot be null.");
    }

    @Override
    public void initialize(C configurableApplicationContext) {
        configurableApplicationContext.addBeanFactoryPostProcessor(this.processor);
    }
    
    /**
     * 所关联的装配件
     * @return {@link ServiceExportableModule}
     */
    public Assembly getAssociatedAssembly() {
    	return this.assembly;
    }
}
